package edu.zut.hb.ambition.cashier.domain;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Cashier;
import com.ruoyi.system.service.ICashierService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/system/cashier")
public class CashierGroup extends BaseController
{
    @Autowired
    private ICashierService cashierService;

    /**
     * 查询门诊缴费列表
     */
    @PreAuthorize("@ss.hasPermi('system:cashier:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cashier cashier)
    {
        startPage();
        List<Cashier> list = cashierService.selectCashierList(cashier);
        return getDataTable(list);
    }

    /**
     * 导出门诊缴费列表
     */
    @PreAuthorize("@ss.hasPermi('system:cashier:export')")
    @Log(title = "门诊缴费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cashier cashier)
    {
        List<Cashier> list = cashierService.selectCashierList(cashier);
        ExcelUtil<Cashier> util = new ExcelUtil<Cashier>(Cashier.class);
        util.exportExcel(response, list, "门诊缴费数据");
    }

    /**
     * 获取门诊缴费详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cashier:query')")
    @GetMapping(value = "/{cashier}")
    public AjaxResult getInfo(@PathVariable("cashier") String cashier)
    {
        return AjaxResult.success(cashierService.selectCashierByCashier(cashier));
    }

    /**
     * 新增门诊缴费
     */
    @PreAuthorize("@ss.hasPermi('system:cashier:add')")
    @Log(title = "门诊缴费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cashier cashier)
    {
        return toAjax(cashierService.insertCashier(cashier));
    }

    /**
     * 修改门诊缴费
     */
    @PreAuthorize("@ss.hasPermi('system:cashier:edit')")
    @Log(title = "门诊缴费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cashier cashier)
    {
        return toAjax(cashierService.updateCashier(cashier));
    }

    /**
     * 删除门诊缴费
     */
    @PreAuthorize("@ss.hasPermi('system:cashier:remove')")
    @Log(title = "门诊缴费", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cashiers}")
    public AjaxResult remove(@PathVariable String[] cashiers)
    {
        return toAjax(cashierService.deleteCashierByCashiers(cashiers));
    }
}
